"""
partial(func, *args, **keywords)
*args : postion argument
**keywords: key argument
"""

from functools import partial


def add(*args):
    return sum(args)


def add_key(*args, **kwargs):
    print("-"*20, end=" ")
    for k, v in kwargs.items():
        print("%s:%s" % (k, v), end=" ")


def mod(name, age, sex):
    return str(name)+'='+str(age)+'='+str(sex)


def partial_def(func, *args, **keywords):
    print(f'partial def args:{args},key args:{keywords}')

    def newfunc(*fargs, **fkeywords):
        print(f'newfunc args:{fargs},key args:{fkeywords}')
        newkeywords = keywords.copy()
        newkeywords.update(fkeywords)
        return func(*args, *fargs, **newkeywords)

    newfunc.func = func
    newfunc.args = args
    newfunc.keywords = keywords
    return newfunc


if __name__ == '__main__':
    partial_func = partial(mod, 12, 13)

    # just add
    ret = partial_func('clear')
    print(ret)  # 12=13=clear

    # args add
    add_100 = partial(add, 100)
    print(add_100(1, 2, 3))  # 106
    add_101 = partial(add, 101)
    print(add_101(1, 2, 3))  # 107

    # key args add
    # partial def args:(1, 2, 3),key args:{'v1': 1, 'v2': 2}
    add_partial = partial_def(add_key, 1, 2, 3, v1=1, v2=2)
    # newfunc args:(2, 3, 4),key args:{'v1': 3, 'v3': 10}
    add_partial(2, 3, 4, v1=3, v3=10)
